

var currentPage = 1;
var status='';//商品状态
var sortTypeId='';//商品分类
sortType();//调用分类方法
//列表
loadMyEssay(status,sortTypeId);

function loadMyEssay(status,sortTypeId) {
	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#collectionGoodsList").html("");
		
		$.ajax({
			url: urlcore + "/api/myCollection/selectPage?status="+status+"&sortTypeId="+sortTypeId+"&current=" + pageNo,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					$.each(data.data.list, function(i, n) {
						
						var shixiao='';
						if(n.goods.status==2){
							shixiao='<div class="wode_shixiao">失效</div>';
						}
						//var coverUrl=n.goods.coverUrl==null?'http://app.jiagangwangluo.com:8080/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/default.png':n.goods.coverUrl;
						coverUrl=isHasImg(n.goods.coverUrl);
						var goodsTitle=n.goods.goodsTitle==null?"暂无":n.goods.goodsTitle;
						var tradePrice=n.goods.tradePrice==null?"0":n.goods.tradePrice;
						var packPrice=n.goods.packPrice==null?"0":n.goods.packPrice;
						var collectNum=n.goods.collectNum==null?"0":n.goods.collectNum;
						
						var thislist =
						'<dl class="wode_shoucang">'+
							'<a href="2.2.0goods_detail.html?id='+n.goods.id+'">'+
								'<dt>'+
									'<img class="collectionGoodsCoverUrlImg" src="'+coverUrl+'" />'+shixiao+
								'</dt>'+
								'<dd>'+
									'<h5>'+goodsTitle+'</h5>'+
									'<h6>&yen;'+tradePrice+'-'+packPrice+'<span>收藏'+collectNum+'</span></h6>'+
								'</dd>'+
							'</a>'+
							'<div class="wode_shoucang_quxiao">'+
								'<input type="checkbox" id="id" name="checkedId" value="'+n.id+'" class="check goods-check goodsCheck1">'+
               					'<span>取消收藏</span>'+
							'</div>'+
						'</dl>';
						
						$('#collectionGoodsList').append(thislist);
						
					});
					
					$(function(){
						var imgList = document.getElementsByClassName("collectionGoodsCoverUrlImg");  
					    var w=288;
					    var h=288;
					    for(var i=0;i<imgList.length;i++){
					        if(imgList[i].width>w || imgList[i].height>h){  
					            imgList[i].width = w;  
					            imgList[i].heigth = h;
					        }  
					    }  
					})

					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					//alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						layer.alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				layer.alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}
//是否失效
function invalid(status){
	loadMyEssay(status,'');
}
//分类查询
function searchBySortType(sortTypeId){
	loadMyEssay('',sortTypeId);
}
//批量收藏
function del() {
	if(!layer.confirm("确定取消收藏吗？")) {
		return;
	}
	var cks = document.getElementsByName("checkedId");
	var arr = new Array();
	
	for(var i = 0; i < cks.length; i++) {
		if(cks[i].checked) {
			arr.push(cks[i].value);
		}
	}
	 $.ajax({
		url: urlcore + "/api/myCollection/delBatchCollection?ids="+arr.toString(),
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				layer.alert("取消成功");
				//刷新
				location.reload();
			}

		},
		error: function() {
			layer.alert("error");
		}
	});
}
//全选/反选
function selectAll() {
 var checkboxs=document.getElementsByName("checkedId");
 for (var i=0;i<checkboxs.length;i++) {
  var e=checkboxs[i];
  e.checked=!e.checked;
 }
}